package cn.edu.xmu.javaee.productwebflux.config;

import cn.edu.xmu.javaee.productwebflux.controller.AdminProductHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.server.*;

@Configuration
public class FunctionModelConfig {

    @Bean
    public RouterFunction<ServerResponse> routerFunction(AdminProductHandler handler) {
        RouterFunction<ServerResponse> router = RouterFunctions.route()
                .GET("/products/{id}", RequestPredicates.accept(MediaType.APPLICATION_JSON), handler::getProductById)
                .build();
        return router;
    }
}
